<template>
  <div>
    <!-- 顶部滑动条 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id==0 ? 'mui-active':'']"
            v-for="item in cates"
            :key="item.id"
            @tap="getPhotoListByCateId(item.id)"
          >{{item.title}}</a>
          <!-- <a
            class="mui-control-item mui-active"
            href="#item1mobile"
            data-wid="tab-top-subpage-1.html"
          >推荐</a>
          <a class="mui-control-item" href="#item2mobile" data-wid="tab-top-subpage-2.html">热点</a>
          <a class="mui-control-item" href="#item3mobile" data-wid="tab-top-subpage-3.html">北京</a>
          <a class="mui-control-item" href="#item4mobile" data-wid="tab-top-subpage-4.html">社会</a>
          <a class="mui-control-item" href="#item5mobile" data-wid="tab-top-subpage-5.html">娱乐</a>
          <a class="mui-control-item" href="#item5mobile" data-wid="tab-top-subpage-5.html">科技</a>-->
        </div>
      </div>
    </div>

    <!-- 图片展示区域 -->
    <ul class="photo-list">
      <!-- <li v-for="item in list" :key="item.id">
        <img v-lazy="item.img_url" />
        <div class="info">
          <h1 class="info-title">{{item.title}}</h1>
          <div class="info-zhaiyao">{{item.zhaiyao}}</div>
        </div>
      </li> -->
      <router-link v-for="item in list" :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
        <img v-lazy="item.img_url" />
        <div class="info">
          <h1 class="info-title">{{item.title}}</h1>
          <div class="info-zhaiyao">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui";

export default {
  data() {
    return {
      cates: [
        { title: "全部", id: 0 },
        { title: "明星", id: 1 },
        { title: "风景", id: 2 },
        { title: "心情图片", id: 3 },
        { title: "宠物", id: 4 },
        { title: "科技风", id: 5 },
        { title: "热爱生辉", id: 6 }
      ], //图片数据
      list: [
        {
          id: 0,
          img_url: "/src/images/1.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 1,
          img_url: "/src/images/2.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 2,
          img_url: "/src/images/3.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 3,
          img_url: "/src/images/4.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 4,
          img_url: "/src/images/5.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 5,
          img_url: "/src/images/3.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 6,
          img_url: "/src/images/4.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        },
        {
          id: 7,
          img_url: "/src/images/5.jpg",
          title: "海边大别墅，风景优美",
          zhaiyao:
            "每次都能杀承诺第三承诺第三祭敖包新手抖啊成绩单窜端匿迹，痴迷大三女不耐烦解答"
        }
      ]
    };
  },
  created() {
    // this.getAllCategory();
    // this.getPhotoListByCateId(0);
  },
  mounted() {
    //当组件中的dom结构被渲染好并放到页面中后，会执行这个钩子函数
    // 如果要操作元素，最好放到mounted中，这里面是最早操作元素的地方
    // 初始化滑动控件
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  // methods: {
  getAllCategory() {
    //   获取所有图片分类
    this.$http.get("api/getimgvategory").then(result => {
      if (result.body.status === 0) {
        // 手动拼接出分类列表
        result.body.message.unshift({ title: "全部", id: 0 });
        this.cates = result.body.message;
      }
    });
  },
  getPhotoListByCateId(cateId) {
    //根据分类id获取图片列表
    this.$http.get("api/getimages/" + cateId).then(result => {
      if (result.body.status === 0) {
        this.list = result.body.message;
      }
    });
  }
  // }
};
</script>
<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
.photo-list {
  list-style: none;
  margin: 0;
  padding: 0 10px;
  padding-bottom:none;
  li {
    text-align: center;
    position:relative;
    margin-bottom:5px;
    img {
      width: 100%;
      height: 200px;
      vertical-align: middle;

    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      color:white;
      background:rgba(0,0,0,.5);
      position:absolute;
      bottom:0px;
      text-align:left;
      line-height:16px;
      .info-title {
        font-size: 14px;
      }
      .info-zhaiyao{
        font-size:13px;
      }
    }
  }
}
</style>
